package com.mavenq.fly.config;

import com.mavenq.fly.commons.thread.ThreadExecuteTool;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;


@Configuration
public class ThreadPoolConfig {

    @Bean(name = "taskExecutor11")
    public TaskExecutor taskExecutor1(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setAllowCoreThreadTimeOut(true);
        executor.setCorePoolSize(2);
        executor.setKeepAliveSeconds(60);
        executor.setMaxPoolSize(4);
        executor.setQueueCapacity(1);
        executor.setThreadFactory(new ThreadExecuteTool.BusThreadFactory());
        // 配置了线程工程不用设置下面的前缀
       // executor.setThreadNamePrefix("afei-");
        executor.setRejectedExecutionHandler(new ThreadExecuteTool.BusRejectedExecutionHandler());
        return executor;
    }


}
